﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PGI.EN.Producto;
using System.Data;
using System.Data.SqlClient;

namespace PGI.AD.Producto
{
    public class MarcaAd
    {
        public static List<MarcaEn> ConsultaMarcasProducto()
        {
            SqlCommand command = null;
            SqlConnection connection = null;
            SqlDataReader reader = null;

            string sql = "MntOpcionProductoS";

            try
            {
                connection = DataBaseFactory.SqlOpenDatabase("PGI");

                command = new SqlCommand(sql, connection);
                command.CommandType = CommandType.StoredProcedure;


                reader = command.ExecuteReader();
                List<MarcaEn> lstMarcaEn = new List<MarcaEn>();
                MarcaEn MarcaEn = null;

                while (reader.Read())
                {
                    MarcaEn = new MarcaEn();
                    MarcaEn.MarcaId = reader.IsDBNull(0) ? 0 : Convert.ToInt32(reader.GetValue(0));                    
                    MarcaEn.Descripcion = reader.IsDBNull(2) ? string.Empty : reader.GetValue(2).ToString();
                    MarcaEn.Estado = reader.IsDBNull(3) ? 0 : Convert.ToInt32(reader.GetValue(3));

                    lstMarcaEn.Add(MarcaEn);
                }

                return lstMarcaEn;
            }

            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (reader != null)
                    reader.Close();
                DataBaseFactory.SqlCloseDatabase("PGI");
            }
        }
    }
}
